<?php
namespace App\Http\Controllers\Api;
use App\Wen\Utils\Settings;
use App\Wen\Utils\Utils;
use App\Models\Shop\WxShopGoods;
use Illuminate\Http\Request;


class ShopGoodsController extends BaseController
{
    public function poster(Request $request){
        $goodsId = $request->id;
        $uid = $request->uid;
        global $__MINI_GLOBAL_TENANT_ID__;

        if(_empty_($goodsId)){
            return $this->fail(200001);
        }

        $good = WxShopGoods::find($goodsId);
        if(_empty_($good)){
            return $this->fail(200003);
        }
        $img_arr = $good->pic;
        $main_img = _array_key($img_arr, 0, Settings::get('img_default', ''));
        $mini_code = Utils::getMiniCode('pagesA/shop/goods-details/goods-details', 'id='.$goodsId, $uid);

        if($mini_code){
            $data = [
                'priceShop'=> $good->price,
                'headImgs' => $img_arr,
                'goodsImg' => $main_img,
                'goodsName' => $good->name,
                'goodsPrice' => $good->vip_price,
                'mainLogo' => Settings::get('about_logo', ''),
                'recommendCodeGoods' => $mini_code,
                'share' => [
                    'shareContent' => $good->intro,
                    'shareImg' => $main_img,
                    'shareTitle' => $good->name,
                    'shareUrl' => Settings::get('app_h5_home') .'/#/pagesA/shop/goods-details/goods-details?id=' . $good->id . '&fph=1&from_user=' . $uid . '&tenant=' .$__MINI_GLOBAL_TENANT_ID__
                ]
            ];

            return $this->success($data);
        }else{
            return $this->fail(300001);
        }
    }
}
